const {formatTime} = require('../../utils/util')

// pages/huifu/huifu.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        replyData: {}
    },

    // 事件处理函数
    // 返回
    goBack() {
        wx.navigateBack({
          delta: 1,
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let {itemId, parentId, itemCommentId} = options
        // console.log(itemId, parentId, itemCommentId);
        wx.request({
          url: 'https://ssl4xyy.metshow.cn/clientxyyservices/itemdetailcomment/list',
          method: 'POST',
          data: {
              query: {
                  parentId,
                  itemId,
                  pageSize: 10,
                  pageIndex: 1
              }
          },
          success: res => {
            //   console.log(res.data.result.Items);
              let items = res.data.result.Items
              let r = items.filter(item => item.ItemCommentId === parseInt(itemCommentId))[0]
              let CreateDate = new Date(parseInt(r.CreateDate.slice(6, -2)))
              console.log(r);
              let i = r.SecondCommentList.Items.map(item => {
                let CreateDate = new Date(parseInt(item.CreateDate.slice(6, -2)))
                return {...item, CreateDate: formatTime(CreateDate).slice(0,-3)}
              })
              let SecondCommentList = {...r.SecondCommentList, Items: i}
              let replyData = {...r, CreateDate: formatTime(CreateDate).slice(0, -3), SecondCommentList}
              console.log(replyData);
            //   console.log(replyData);
              this.setData({
                  replyData
              })
          }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})